package com.iogogogo.supervisord4j.base.configuration;

import com.iogogogo.supervisord.properties.SupervisordProperties;
import com.iogogogo.supervisord4j.properties.InstanceProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * Created by tao.zeng on 2021/7/12.
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(InstanceProperties.class)
public class MultiInstanceAutoConfiguration {

    @Bean
    public MultiInstanceConfigure multiInstanceConfigure(Environment environment) {
        Binder binder = Binder.get(environment);
        InstanceProperties properties = binder.bind(SupervisordProperties.SUPERVISORD_PREFIX, InstanceProperties.class).get();
        MultiInstanceConfigure multiInstanceConfigure = new MultiInstanceConfigure();
        multiInstanceConfigure.setInstanceProperties(properties);
        return multiInstanceConfigure;
    }
}
